#pragma once;
#include <vector>

#include "common.h"
#include "rigidbody.h"
#include "physics_object.h"
#include "contact.h"
#include "contact_resolver.h"

namespace TorPhysix
{
class World
{
public:
	World();
	~World(){}
	void startFrame();
	void runPhysics(real dt);

	void addBody( RigidBody *newBody );
	void addPhysicsObject( PhysicsObject *newPhysObj );
	void clear();

	struct PerfCounter
	{
		int contactsGeneratedLast;
		int maxContacts;
		int posItersMax;
		int posItersUsed;
		int velItersMax;
		int velItersUsed;
	};
	struct PerfCounter performance;
private:
	void generateContacts();
	
	// Holds a singly linked list of bodies
	struct BodyRegistration
	{
		RigidBody *body;
		BodyRegistration *next;
	};

	// Head of body linked list
	BodyRegistration *firstReg;

	std::vector<PhysicsObject*> physObjList;
	std::vector<Contact> contacts;
	CollisionData cData;
	ContactResolver resolver;
	
};
}